<%@ page language="java" contentType="text/html; charset=UTF8" pageEncoding="UTF8"%>
<%@ page import="java.util.*" %>
<%@ page import="bcnet.service.PriceHistoryService" %>
<%@ page import="bcnet.service.factory.PriceHistoryServiceFactory" %>
<%@ page import="bcnet.domain.CodeVO" %>
<%

	Calendar cal = Calendar.getInstance();
	cal.add(Calendar.HOUR, +8);
	Date todayDate = cal.getTime();
	
	boolean force = request.getParameter("force")==null?false:Boolean.getBoolean(request.getParameter("force"));
	
	int dow = cal.get (Calendar.DAY_OF_WEEK);
	boolean isWeekday = ((dow >= Calendar.MONDAY) && (dow <= Calendar.FRIDAY));
	
	if(isWeekday || force){ // only run the cron at weekday or force=true
		int fromCode = request.getParameter("fromCode")==null?1:Integer.parseInt(request.getParameter("fromCode"));
		int toCode = request.getParameter("toCode")==null?9999:Integer.parseInt(request.getParameter("toCode"));
		
		PriceHistoryService priceHistoryService = PriceHistoryServiceFactory.getPriceHistoryService();
		List<CodeVO> codeList = priceHistoryService.getCodeFullList(fromCode,toCode);
		
		priceHistoryService.deleteCache("mailSent");
		priceHistoryService.deleteCache("buyList");
		priceHistoryService.deleteCache("sellList");
		priceHistoryService.deleteCache("boughtCodeListString");
		priceHistoryService.addTask(codeList);
	}

%>
